<template>
    <div class="contain">
        <div class="input_modal">
            <div class="input-item">
                <el-input v-model="searchWord" placeholder="请输入用户ID" class="proName"  @keyup.enter.native="search"></el-input>
                 <el-button type="primary" @click="getUserList">查询用户</el-button>
            </div>
        </div>
        
        <div class="table_con">
            <el-table :data="tableData" stripe style="width: 100%">
                <el-table-column prop="id" label="用户ID" style="width: 20%">
                </el-table-column>
                <el-table-column prop="userName" label="用户昵称" style="width: 20%">
                </el-table-column>
                <el-table-column prop="mobile" label="手机号码" style="width: 20%">
                </el-table-column>
                <el-table-column prop="createdDate" label="注册日期" style="width: 20%">
                </el-table-column>
                <el-table-column  prop="id"  label="操作" fixed="right" width='150'>
                    <template slot-scope="scope">
                        <el-button type="danger" size="mini" @click="deleteItem(tableData[scope.$index].id)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <div class="pagination">
             <el-pagination   @size-change="handleSizeChange"  @current-change="handleCurrentChange"       
                :current-page.sync="pageIndex"              
                :page-size="pageSize"   
                :page-sizes='[10,20,30,40]'    
                layout="sizes, prev, pager, next"       
                :total="pageCount">     
            </el-pagination>
        </div>
    </div>
</template>

<script>
let CONSTANT = require('../../constant/constant.js');
let common = require("../../common.js");
export default {
    data() {
        var validateNumber = (rules,value,callback)=>{
          if(isNaN(value)) {
              callback(new Error('请输入数字值!'));
          }
          else {
              callback();
          }
        }
        
        return {
            searchWord:'',
            id:'',
            userName:'',
            mobile:'',
            createdDate:'',
            tableData:[],
            pageCount:null,
            pageIndex:1,
            pageSize:10,
            loading:true,
            dialogVisible:false,
            dialogTitle:'操作提示',
            dialogType:'camp',
            dialogImageUrl:'',
            information: {
                
            },
            rules: {
                
            },
        }
    },
    mounted() {
        this.getUserList();
    },
    methods: {
        getUserList:function(){  // FINDAPPUSERBYPAGE
           let url = CONSTANT.URL.USER.FINDAPPUSERCOREBYPAGE;
           let dataForm = {
               pageIndex:this.pageIndex,
               pageSize:this.pageSize
           }
           let data = {
           } ;
           if(this.searchWord != ''){
                data.searchWord = this.searchWord;
           }
           
           let param = JSON.stringify(data);
           this.loading = true;
            common.requestAjax(url,param,dataForm,(res)=>{
                this.loading = false;
                let data = res.data;
                // console.log('用户列表---', data);
                this.tableData = data.bussData;
                this.pageCount = data.pageCount*this.pageSize;
            }) 
        },
        search:function(e){
            if(e.keyCode == 13){
                this.getUserList(1);
                this.pageIndex = 1; 
            }
        },
        deleteItem:function(userId){
            this.$confirm('确定删除?', '提示', {           
                confirmButtonText: '确定',           
                cancelButtonText: '取消',           
                type: 'warning'         
            }).then(() => {           
                let  url = CONSTANT.URL.USER.DELAPPUSER;
                let param = {userId:userId};
                common.requestAjax(url,param,null,(res)=>{
                    if(res.status == 200){
                        this.$message({
                            type:'success',
                            message:'删除成功!'
                        });
                        this.getUserList();
                    }
                    else{
                        this.$message({
                            type:'warning',
                            message:res.msg
                        })
                    }
                })      
            }).catch(() => {           
                this.$message({             
                    type: 'info',             
                    message: '已取消删除'           
                });                   
            });    
        },
        handleSizeChange(val) {
            this.pageSize= val;
            this.getUserList(this.pageIndex);
        },
        handleCurrentChange(val) {
            this.getUserList(val);
            this.pageIndex = val;
        },
        handleClose(){
            this.dialogVisible = false;
        },
     
    },
    filters:{
    }
}
</script>

<style lang="scss" scoped>
    .contain {
         .header{
            margin: 20px 0;
            padding-bottom: 10px;
            border-bottom:1px solid #dedede; 
        }
        .input_modal {
            margin-top: 20px;
            .input-item{ 
                display: inline-block;
                margin-right: 20px;
                clear: both;
                height: 40px;
                line-height: 40px;
                .el-input,.el-button, .el-select,span{ float: left;margin-right: 10px;}
                .proName{width:200px;}
            }
        }
        .el-dialog__body{
            // padding:  10px 20px;
            .dialog-con{
                padding:0px 20px 0px 0px;
                p{  text-align: center;margin:5px 0px 20px 0px;font-size: 14px;color: #666;
                    span{
                        color: #111;font-size: 14px;
                    }
                }
            }
        }
        .table_con{
            text-align: center;
            // .el-button{
            //     display: inline-block;
            //     width: 104px;
            //     height: 30px;
            //     margin-left: 0;
            //     margin-top: 5px;
            // }
            // .el-button:nth-child(3){
            //      margin-top: 5px;
            // }
        }
        .pagination {
            text-align: right;
            width: 100%;
            margin-top: 60px;
        }
    }
</style>
